package io.github.jesse205.dragdrop.pro.app

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import io.github.jesse205.dragdrop.pro.manager.ThemeManager
import rikka.insets.WindowInsetsHelper
import rikka.layoutinflater.view.LayoutInflaterFactory

abstract class BaseActivity : AppCompatActivity() {

    val themeManager: ThemeManager by lazy {
        ThemeManager(this)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        layoutInflater.factory2 = LayoutInflaterFactory(delegate)
            .addOnViewCreatedListener(WindowInsetsHelper.LISTENER)
        // 使用我们自己的处理方式，UI 更和谐。
        // enableEdgeToEdge()
        super.onCreate(savedInstanceState)
        themeManager.applyTheme()
    }

    override fun onResume() {
        super.onResume()
        if (themeManager.isThemeChanged()) {
            recreate()
        }
    }
}